import { UserInfo } from '@prisma/client';
import { TX } from '../db';

type CreateData = {
  userId: bigint;
  nickname: string;
  avatar: string;
  description: string;
};

async function create(tx: TX, data: CreateData): Promise<UserInfo> {
  const now = new Date();
  return tx.userInfo.create({
    data: {
      userId: data.userId,
      nickname: data.nickname,
      avatar: data.avatar,
      description: data.description,
      createTime: now,
      updateTime: now,
    },
  });
}

async function findByUserId(tx: TX, userId: bigint): Promise<UserInfo | null> {
  return tx.userInfo.findFirst({ where: { userId } });
}

export const userInfoService = {
  create,
  findByUserId,
};
